﻿namespace Trove
{
    using System;
    using System.IO;

    using Cavity;
    using Cavity.Reflection;

    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;

    using Trove.Web;

    using Xunit;

    public sealed class Mvc3Facts
    {
        [Comment("Only run on the local dev machine.")]
        public void chrome()
        {
            // ReSharper disable PossibleNullReferenceException
            var path = Path.Combine(GetType().Assembly.Directory().Parent.Parent.Parent.Parent.FullName, @"Web Applications\Mvc3");

            // ReSharper restore PossibleNullReferenceException
            using (new IisExpress(new DirectoryInfo(path), 2323))
            {
                IWebDriver driver = null;
                try
                {
                    driver = new ChromeDriver();
                    var nav = driver.Navigate();
                    nav.GoToUrl(new Uri("http://localhost:2323/"));

                    Assert.Equal("MVC3 Verification", driver.Title);
                }
                finally
                {
                    if (null != driver)
                    {
                        driver.Close();
                    }
                }
            }
        }
    }
}